<?php

if(!defined('IN_refrigeratory')) {
	exit('Access Denied');
}

$operation = $_REQUEST["operation"];
$operations = array("info_chart_equip","info_chart_medicine");

if (!in_array($operation, $operations)){
	echo '{"success":false, "info":"request params invalid"}';
	exit;
}

if ($operation == "info_chart_equip"){
	$id_equip = $_REQUEST["id_equip"];
	$get_temp = $_REQUEST["get_temp"];
	$get_humidity = $_REQUEST["get_humidity"];
	$return_str  = ''; 
	if($get_temp == true ){
		 $sql = "SELECT UNIX_TIMESTAMP(time)*1000 time ,temp FROM t_temp WHERE id_equipment = $id_equip ORDER BY time LIMIT 0,30";
	}
	else if ($get_humidity == true){
	}
	echo get_json_from_sql($sql);
}


if ($operation == "info_chart_medicine"){
	$id_medicine = $_REQUEST["id_medicine"];
	$id_batch = $_REQUEST["id_batch"];
	
	$get_temp = $_REQUEST["get_temp"];
	$get_humidity = $_REQUEST["get_humidity"];
	$return_str  = ''; 
	if($get_temp == true ){
		 $sql = "SELECT UNIX_TIMESTAMP(time)*1000 time ,temp 
				FROM t_temp
				WHERE id_equipment = (
					SELECT id_equipment 
					FROM  t_storage_room 
					where id_storage_room in (
						SELECT id_storage_room FROM t_order o
						LEFT JOIN t_batch b ON o.id_batch = b.id_batch 
							AND o.id_medicine = b.id_medicine
						)
				) ORDER BY time LIMIT 0,30" ;
	}
	
	else if ($get_humidity == true){
	}
	echo get_json_from_sql($sql);
}


?>